package com.greatwall.hip.cms.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.greatwall.hip.cms.model.Result;

import javax.servlet.ServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author TianLei
 * @version V1.0
 */
public class WebUtil {

    static ObjectMapper objectMapper = new ObjectMapper();

    public static void sendResponse(ServletResponse response, Result body) throws IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        try (PrintWriter out = response.getWriter()){
            out.print(objectMapper.writeValueAsString(body));
        }
    }
}
